﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication9.Models;

namespace MvcApplication9.Controllers
{ 
    public class SubmitController : Controller
    {
        private MainModelContainer db = new MainModelContainer();

        static int Id;
        static DateTime Date;
        

        public ViewResult Details(int id)
        {
            Submit submit = db.Submits.Single(s => s.Id == id);
            ViewBag.Ship = (from i in db.Ships where i.Id == submit.CruiseID select i).FirstOrDefault();
            return View(submit);
        }

        //
        // GET: /Submit/Create

        public ActionResult Create(int id,DateTime date)
        {
            Id = id;
            Date = date;
            return View();
        } 

        //
        // POST: /Submit/Create

        [HttpPost]
        public ActionResult Create(Submit submit)
        {
            if (ModelState.IsValid)
            {
                submit.SubmitDate = Date.ToString();
                submit.CruiseID = Id;
                db.Submits.AddObject(submit);
                db.SaveChanges();
                return RedirectToAction("Index","Home");  
            }

            return View(submit);
        }
         
        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}